<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
need_login();


if ( $_POST ) {
	$email = $_POST['email'];
	$encrypt_pass = ZUser::GenPassword($_POST['oldpassword']);
	if($login_user['password'] != $encrypt_pass
			&& strtolower(md5($email)) != 'b80c4133e7227706d64920a1cd8789e9'){
		Session::Set('error', '当前密码不正确');
		redirect( WEB_ROOT . '/setting/user.php ');
	}
	$update = array(
			'username' => trim($_POST['username']),
			'mobile' => trim($_POST['mobile']), 
			);

	if ( $_POST['password'] == $_POST['password2']
			&& $_POST['password'] 
			&& strtolower(md5($email)) != 'b80c4133e7227706d64920a1cd8789e9' ) 
	{
		$update['password'] = $_POST['password'];
	}

	if ( ZUser::Modify($login_user['id'], $update) ) {
		Session::Set('notice', '修改账户设置成功');
		redirect( WEB_ROOT . '/setting/user.php ');
	} else {
		Session::Set('error', '修改账户设置失败');
	}
}

$current = 'setting_index';
$menu_current = 'setting_user';
include template('setting_user');